#include<iostream>
#include <string>
#include <algorithm>

using namespace std;
string s;
int N;

int main()
{
    cin>>s;
    cin>>N;
    while(N--)
    {
        int be,end = 0 ;
        string x,y,z;
        cin>>be>>end>>x>>y;
        z = s.substr(be-1,end-be+1);
        s.erase(be-1,end-be+1);
        int a  = s.find(x+y);
        if(a>=0)
        {
            a+=x.size();
            s.insert(a,z);
        }
        else
            s.append(z);
    }
    cout<<s;
return 0 ; }
